home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power CD-ROM!! 8
/
Power CD-ROM 8.iso
/
prgmming
/
pmd110
/
ems.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1994-11-13
|
5KB
|
99 lines
(* This file was mangled by Mangler 1.35 (c) Copyright 1993-1994 by Berend de Boer *)
{ Created : 1994-09-08 (c) Copyright 1994 by Berend de Boer
EMS unit created from ObjMemory. Implements subset of EMS functions.
Needs EMS 4.0!
Last changes :
}
{$IFNDEF MsDos}
Error
{$ENDIF}
{$F+,O+,X+}
unit EMS;
interface
const
_16K = $4000;
type
TEMSHandle = word;
type
EMSAddrStruct = record
MemType : (emsConventional, emsExpanded);
Handle : TEMSHandle;
case integer of
0 : (Offs : word;
LPage : word);
1 : (Ptr : pointer);
end;
type
EMSMoveStruct = record
Count : longint;
Source : EMSAddrStruct;
Dest : EMSAddrStruct;
end;
const
EMSInstalled:Boolean = FALSE; {* set by calling ems_init *}
EMSVersion:byte = 0; {* set by ems_init *}
EMSResult:byte = 0; {* result of last int 67h call *}
EMSFrame:pointer = nil; {* EMS page frame *}
procedure ems_init;
function ems_allocate(var Handle : TEMSHandle; var TotalPages : word; Size : longint) : Boolean;
function ems_dispose(Handle : TEMSHandle) : Boolean;
function ems_get_version : Boolean;
function ems_get_frame : Boolean;
function ems_get_status : byte;
procedure ems_map_memory(Handle : TEMSHandle; PhysicalPage : byte; LogicalPage : word);
procedure ems_move_region(SourceHandle : TEMSHandle; SourceOffs : longint;
DestHandle : TEMSHandle; DestOffs : longint;
Count : longint);
function ems_number_of_pages : word;
function ems_present : Boolean;
IMPLEMENTATION {$IFDEF Debug}USES ASSERTIONS ;{$ENDIF}PROCEDURE EMS_INIT ;BEGIN IF NOT EMS_PRESENT THEN EXIT ;IF NOT
EMS_GET_VERSION OR (EMSVERSION < $40 )THEN EXIT ;IF NOT EMS_GET_FRAME THEN EXIT ;EMSINSTALLED := TRUE ;END ;
FUNCTION EMS_ALLOCATE (VAR HANDLE:TEMSHANDLE;VAR TOTALPAGES:WORD;SIZE:LONGINT):BOOLEAN ;ASSEMBLER;ASM {}
MOV AX , WORD PTR SIZE{} MOV DX , WORD PTR SIZE+ 2 {} MOV CX , 4000h {} DIV CX {} CMP DX , 0 {} JZ @1 {} INC AX {}
@1 : {} MOV BX , AX {} LES DI , TOTALPAGES{} MOV WORD PTR ES : [ DI ] , BX {} MOV AH , 43h {} INT 67h {}
MOV EMSRESULT, AH {} CMP AH , 0 {} JZ @ok {} @error : {} XOR AX , AX {} LES DI , HANDLE{}
MOV WORD PTR ES : [ DI ] , AX {} JMP @end {} @ok : {} LES DI , HANDLE{} MOV WORD PTR ES : [ DI ] , DX {} MOV AX , 1 {}
@end : {} END;FUNCTION EMS_DISPOSE (HANDLE:TEMSHANDLE):BOOLEAN ;ASSEMBLER;ASM {} MOV DX , HANDLE{} MOV AH , 45h {}
INT 67h {} MOV EMSRESULT, AH {} MOV AL , 1 {} CMP AH , 0 {} JZ @end {} XOR AX , AX {} @end : {} END;
FUNCTION EMS_GET_FRAME :BOOLEAN ;ASSEMBLER;ASM {} MOV AH , 41h {} INT 67h {} MOV EMSRESULT, AH {}
MOV WORD PTR EMSFRAME+ 2 , BX {} MOV AL , 1 {} CMP AH , 0 {} JZ @end {} XOR AX , AX {} @end : {} END;
FUNCTION EMS_GET_VERSION :BOOLEAN ;ASSEMBLER;ASM {} MOV AH , 46h {} INT 67h {} MOV EMSRESULT, AH {} MOV EMSVERSION, AL {}
MOV AL , 1 {} CMP AH , 0 {} JZ @end {} XOR AX , AX {} @end : {} END;FUNCTION EMS_GET_STATUS :BYTE ;ASSEMBLER;ASM {}
MOV AH , 040h {} INT 67h {} MOV AL , AH {} XOR AH , AH {} END;PROCEDURE EMS_MAP_MEMORY (HANDLE:TEMSHANDLE;
PHYSICALPAGE:BYTE;LOGICALPAGE:WORD);ASSEMBLER;ASM {} MOV AL , PHYSICALPAGE{} MOV AH , 044h {} MOV BX , LOGICALPAGE{}
MOV DX , HANDLE{} INT 67h {} MOV EMSRESULT, AH {} END;PROCEDURE EMS_MOVE_REGION (SOURCEHANDLE:TEMSHANDLE;
SOURCEOFFS:LONGINT;DESTHANDLE:TEMSHANDLE;DESTOFFS:LONGINT;COUNT:LONGINT);VAR OIOI101O0I:EMSMOVESTRUCT;
BEGIN WITH OIOI101O0I DO BEGIN WITH SOURCE DO BEGIN HANDLE := SOURCEHANDLE ;IF HANDLE =0 THEN BEGIN MEMTYPE :=
EMSCONVENTIONAL ;PTR := POINTER (SOURCEOFFS );END ELSE BEGIN MEMTYPE := EMSEXPANDED ;LPAGE := SOURCEOFFS DIV _16K ;OFFS
:= SOURCEOFFS MOD _16K ;END ;END ;WITH DEST DO BEGIN HANDLE := DESTHANDLE ;IF HANDLE =0 THEN BEGIN MEMTYPE :=
EMSCONVENTIONAL ;PTR := POINTER (DESTOFFS );END ELSE BEGIN MEMTYPE := EMSEXPANDED ;LPAGE := DESTOFFS DIV _16K ;OFFS :=
DESTOFFS MOD _16K ;END ;END ;END ;OIOI101O0I.COUNT := COUNT ;ASM {} PUSH DS {} MOV AX , SS {} MOV DS , AX {}
LEA SI , OIOI101O0I{} MOV AX , 5700h {} INT 67h {} POP DS {} MOV EMSRESULT, AH {} END;END ;FUNCTION EMS_NUMBER_OF_PAGES
:WORD ;ASSEMBLER;ASM {} MOV AH , 42h {} INT 67h {} MOV EMSRESULT, AH {} MOV AX , BX {} END;FUNCTION EMS_PRESENT :BOOLEAN
;ASSEMBLER;CONST O1lO1llIO0OO:ARRAY [ 0 .. 8 ] OF CHAR='EMMXXXX0'#0;ASM {} PUSH DS {} MOV DX , SEG O1lO1llIO0OO{}
MOV DS , DX {} MOV DX , OFFSET O1lO1llIO0OO{} MOV AX , 3d00h {} INT 21h {} JC @error {} MOV BX , AX {} MOV AX , 4400h {}
INT 21h {} JC @error {} AND DX , 80h {} JZ @error {} MOV AX , 4407h {} INT 21h {} JC @error {} OR AL , AL {} JZ @error {}
MOV AH , 3eh {} INT 21h {} JC @error {} MOV AX , 1 {} JMP @end {} @error : {} MOV AX , 0 {} @end : {} POP DS {} END;
END .